package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {
    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入菜品数据
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 根据id删除菜品
     * @param id
     */
    @Delete("delete from dish where dish.id = #{id}")
    void deleteById(Long id);

    /**
     * 删除集合内的菜品
     * @param dishIds
     */
    void deleteByIds(List<Long> dishIds);

    /**
     *
     * 修改菜品信息
     * @param dishDTO
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dishDTO);

    /**
     * 根据分类id查询菜品
     *
     * @param categoryId
     */
    @Select("select * from dish where status = 1 and category_id = #{categoryId} order by create_time desc")
    List<Dish> getByCategoryID(Long categoryId);


}
